package com.four.reimbursemanage.service.impl;

import com.four.reimbursemanage.common.bean.Page;
import com.four.reimbursemanage.dao.OutmemberApplyMapper;
import com.four.reimbursemanage.entity.OutmemberApply;
import com.four.reimbursemanage.entity.Payapply;
import com.four.reimbursemanage.service.OutmemberApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OutmemberApplyServiceImpl implements OutmemberApplyService {

    @Autowired
    OutmemberApplyMapper outmemberApplyMapper;
    @Override
    public Page<OutmemberApply> getOnrePage(int pageNum, int pageSize, Date outdate, Integer state) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<OutmemberApply> list=outmemberApplyMapper.selectOutmemberList(start,pageSize, outdate, state);
        //获取总条目数
        int total=outmemberApplyMapper.countOutmemberApply(outdate, state);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<OutmemberApply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    @Override
    public Page<OutmemberApply> getOnrePageUser(int pageNum, int pageSize, Date outdate, Integer state, String number) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<OutmemberApply> list=outmemberApplyMapper.selectUser(start,pageSize, outdate, state, number);
        //获取总条目数
        int total=outmemberApplyMapper.countOutmemberApplyUser(outdate, state, number);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<OutmemberApply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    /*撤销*/
    @Override
    public boolean updateC(OutmemberApply outmemberApply) {
        if (outmemberApply == null){
            return false;
        }
        outmemberApply.setState(3);
        return outmemberApplyMapper.updateStateById(outmemberApply)>0;
    }

    @Override
    public boolean insertOutmemberApply(OutmemberApply outmemberApply) {
        if (outmemberApply == null){
            return false;
        }
        return outmemberApplyMapper.insertOutmemberApply(outmemberApply)>0;
    }

    @Override
    public boolean updateOutmemberApply(OutmemberApply outmemberApply) {
        if (outmemberApply == null){
            return false;
        }
        return outmemberApplyMapper.updateOutmemberApply(outmemberApply)>0;
    }
}
